package lion.soa.dubbo;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.dubbo.config.ServiceConfig;

import lion.dev.lang.Init;
import lion.framework.core.anno.Initializer;
import lion.framework.core.bean.BeanFactory;
import lion.soa.dubbo.anno.DubboRef;

/**
 * 
 * Ali Dubbo SOA Component Initializer
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2016年4月18日
 */
@Initializer
public class DubboInitializer implements Init {

	@Override
	public void init() {

		List<DubboRef> refs = DubboServiceManager.getDubboRefs();
		List<ServiceConfig<?>> serviceConfigs = new ArrayList<>();
		for (DubboRef ref : refs) {
			ServiceConfig<Object> sc = new ServiceConfig<>();
			sc.setInterface(ref.getInterfaceClass());
			sc.setRef(BeanFactory.create(ref.getServiceClass()));
			serviceConfigs.add(sc);
		}
		for (ServiceConfig<?> sc : serviceConfigs) {
			sc.export();
		}
	}

	@Override
	public int order() {

		return 999;
	}

}
